<?php

/**
 * This is the model class for table "po".
 *
 * The followings are the available columns in table 'po':
 * @property string $po
 * @property string $po_number_seq
 * @property string $po_date
 * @property string $revision_number
 * @property string $revision_date
 * @property string $payment_term1
 * @property string $deliver_to
 * @property string $delivery_term
 * @property string $time_of_delivery
 * @property string $eta_jakarta
 * @property integer $shipment_method
 * @property string $port_of_discharge
 * @property string $awb_bl
 * @property integer $po_type
 * @property integer $id_user_prepared
 * @property integer $id_user_checked
 * @property integer $id_user_approved
 * @property string $currency_code
 * @property string $exchange_rate
 * @property string $discount_amount
 * @property string $discount_percent
 * @property string $percent_vat
 * @property string $npwp
 * @property string $skep_kawasan_berikat
 * @property string $remark1
 * @property string $remark2
 * @property string $remark3
 * @property string $remark4
 * @property string $remark5
 * @property string $supplier_code
 * @property integer $status
 * @property string $quotation_request_number
 * @property string $payment_term2
 * @property string $id_section
 * @property string $po_number
 * @property string $purchase_requisition_number
 * @property string $supplier_id
 * @property string $lead_time
 * @property string $supplier
 * @property integer $canView
 */
class Po extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Po the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'po';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('shipment_method, po_type, id_user_prepared, id_user_checked, id_user_approved, status, canView', 'numerical', 'integerOnly'=>true),
			array('po_number_seq, id_section, po_number, purchase_requisition_number, supplier', 'length', 'max'=>50),
			array('currency_code', 'length', 'max'=>3),
			array('exchange_rate, discount_amount, discount_percent, percent_vat', 'length', 'max'=>8),
			array('supplier_id, lead_time', 'length', 'max'=>19),
			array('po_date, revision_number, revision_date, payment_term1, deliver_to, delivery_term, time_of_delivery, eta_jakarta, port_of_discharge, awb_bl, npwp, skep_kawasan_berikat, remark1, remark2, remark3, remark4, remark5, supplier_code, quotation_request_number, payment_term2', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('po, po_number_seq, po_date, revision_number, revision_date, payment_term1, deliver_to, delivery_term, time_of_delivery, eta_jakarta, shipment_method, port_of_discharge, awb_bl, po_type, id_user_prepared, id_user_checked, id_user_approved, currency_code, exchange_rate, discount_amount, discount_percent, percent_vat, npwp, skep_kawasan_berikat, remark1, remark2, remark3, remark4, remark5, supplier_code, status, quotation_request_number, payment_term2, id_section, po_number, purchase_requisition_number, supplier_id, lead_time, supplier, canView', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'po' => 'Po',
			'po_number_seq' => 'Po Number Seq',
			'po_date' => 'Po Date',
			'revision_number' => 'Revision Number',
			'revision_date' => 'Revision Date',
			'payment_term1' => 'Payment Term1',
			'deliver_to' => 'Deliver To',
			'delivery_term' => 'Delivery Term',
			'time_of_delivery' => 'Time Of Delivery',
			'eta_jakarta' => 'Eta Jakarta',
			'shipment_method' => 'Shipment Method',
			'port_of_discharge' => 'Port Of Discharge',
			'awb_bl' => 'Awb Bl',
			'po_type' => 'Po Type',
			'id_user_prepared' => 'Id User Prepared',
			'id_user_checked' => 'Id User Checked',
			'id_user_approved' => 'Id User Approved',
			'currency_code' => 'Currency Code',
			'exchange_rate' => 'Exchange Rate',
			'discount_amount' => 'Discount Amount',
			'discount_percent' => 'Discount Percent',
			'percent_vat' => 'Percent Vat',
			'npwp' => 'Npwp',
			'skep_kawasan_berikat' => 'Skep Kawasan Berikat',
			'remark1' => 'Remark1',
			'remark2' => 'Remark2',
			'remark3' => 'Remark3',
			'remark4' => 'Remark4',
			'remark5' => 'Remark5',
			'supplier_code' => 'Supplier Code',
			'status' => 'Status',
			'quotation_request_number' => 'Quotation Request Number',
			'payment_term2' => 'Payment Term2',
			'id_section' => 'Id Section',
			'po_number' => 'Po Number',
			'purchase_requisition_number' => 'Purchase Requisition Number',
			'supplier_id' => 'Supplier',
			'lead_time' => 'Lead Time',
			'supplier' => 'Supplier',
			'canView' => 'Can View',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('po',$this->po,true);
		$criteria->compare('po_number_seq',$this->po_number_seq,true);
		$criteria->compare('po_date',$this->po_date,true);
		$criteria->compare('revision_number',$this->revision_number,true);
		$criteria->compare('revision_date',$this->revision_date,true);
		$criteria->compare('payment_term1',$this->payment_term1,true);
		$criteria->compare('deliver_to',$this->deliver_to,true);
		$criteria->compare('delivery_term',$this->delivery_term,true);
		$criteria->compare('time_of_delivery',$this->time_of_delivery,true);
		$criteria->compare('eta_jakarta',$this->eta_jakarta,true);
		$criteria->compare('shipment_method',$this->shipment_method);
		$criteria->compare('port_of_discharge',$this->port_of_discharge,true);
		$criteria->compare('awb_bl',$this->awb_bl,true);
		$criteria->compare('po_type',$this->po_type);
		$criteria->compare('id_user_prepared',$this->id_user_prepared);
		$criteria->compare('id_user_checked',$this->id_user_checked);
		$criteria->compare('id_user_approved',$this->id_user_approved);
		$criteria->compare('currency_code',$this->currency_code,true);
		$criteria->compare('exchange_rate',$this->exchange_rate,true);
		$criteria->compare('discount_amount',$this->discount_amount,true);
		$criteria->compare('discount_percent',$this->discount_percent,true);
		$criteria->compare('percent_vat',$this->percent_vat,true);
		$criteria->compare('npwp',$this->npwp,true);
		$criteria->compare('skep_kawasan_berikat',$this->skep_kawasan_berikat,true);
		$criteria->compare('remark1',$this->remark1,true);
		$criteria->compare('remark2',$this->remark2,true);
		$criteria->compare('remark3',$this->remark3,true);
		$criteria->compare('remark4',$this->remark4,true);
		$criteria->compare('remark5',$this->remark5,true);
		$criteria->compare('supplier_code',$this->supplier_code,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('quotation_request_number',$this->quotation_request_number,true);
		$criteria->compare('payment_term2',$this->payment_term2,true);
		$criteria->compare('id_section',$this->id_section,true);
		$criteria->compare('po_number',$this->po_number,true);
		$criteria->compare('purchase_requisition_number',$this->purchase_requisition_number,true);
		$criteria->compare('supplier_id',$this->supplier_id,true);
		$criteria->compare('lead_time',$this->lead_time,true);
		$criteria->compare('supplier',$this->supplier,true);
		$criteria->compare('canView',$this->canView);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function search2($id)
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
		$criteria->condition = "supplier_id=".$id;
		$criteria->compare('po',$this->po,true);
		$criteria->compare('po_number_seq',$this->po_number_seq,true);
		$criteria->compare('po_date',$this->po_date,true);
		$criteria->compare('revision_number',$this->revision_number,true);
		$criteria->compare('revision_date',$this->revision_date,true);
		$criteria->compare('payment_term1',$this->payment_term1,true);
		$criteria->compare('deliver_to',$this->deliver_to,true);
		$criteria->compare('delivery_term',$this->delivery_term,true);
		$criteria->compare('time_of_delivery',$this->time_of_delivery,true);
		$criteria->compare('eta_jakarta',$this->eta_jakarta,true);
		$criteria->compare('shipment_method',$this->shipment_method);
		$criteria->compare('port_of_discharge',$this->port_of_discharge,true);
		$criteria->compare('awb_bl',$this->awb_bl,true);
		$criteria->compare('po_type',$this->po_type);
		$criteria->compare('id_user_prepared',$this->id_user_prepared);
		$criteria->compare('id_user_checked',$this->id_user_checked);
		$criteria->compare('id_user_approved',$this->id_user_approved);
		$criteria->compare('currency_code',$this->currency_code,true);
		$criteria->compare('exchange_rate',$this->exchange_rate,true);
		$criteria->compare('discount_amount',$this->discount_amount,true);
		$criteria->compare('discount_percent',$this->discount_percent,true);
		$criteria->compare('percent_vat',$this->percent_vat,true);
		$criteria->compare('npwp',$this->npwp,true);
		$criteria->compare('skep_kawasan_berikat',$this->skep_kawasan_berikat,true);
		$criteria->compare('remark1',$this->remark1,true);
		$criteria->compare('remark2',$this->remark2,true);
		$criteria->compare('remark3',$this->remark3,true);
		$criteria->compare('remark4',$this->remark4,true);
		$criteria->compare('remark5',$this->remark5,true);
		$criteria->compare('supplier_code',$this->supplier_code,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('quotation_request_number',$this->quotation_request_number,true);
		$criteria->compare('payment_term2',$this->payment_term2,true);
		$criteria->compare('id_section',$this->id_section,true);
		$criteria->compare('po_number',$this->po_number,true);
		$criteria->compare('purchase_requisition_number',$this->purchase_requisition_number,true);
		$criteria->compare('supplier_id',$this->supplier_id,true);
		$criteria->compare('lead_time',$this->lead_time,true);
		$criteria->compare('supplier',$this->supplier,true);
		$criteria->compare('canView',$this->canView);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}